<template>
  <div id="jobList">
    <el-input size="small" @keyup.enter.native="searchHandle" style="width: 300px" v-model="keywords"
              placeholder="搜索职位、发布账号或所属企业名称"></el-input>
    <el-button @click="searchHandle()" style="margin-left: 10px" type="primary" icon="el-icon-search" size="small">搜索
    </el-button>
    <el-table
        height="536"
        :data="jobList"
        v-loading="loading"
        element-loading-text="拼命加载中"
        style="width: 99.5%">
      <el-table-column
          label="序号"
          align="center"
          type="index"
          :index="indexMethod">
      </el-table-column>
      <el-table-column
          label="职位名称"
          prop="jobName"
          align="center"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="发布账号"
          prop="userName"
          align="center"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="所属企业"
          align="center"
          prop="companyName"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="所在城市"
          prop="cityCode"
          align="center"
          show-overflow-tooltip>
        <template slot-scope="scope">
          {{codeToCity(scope.row.cityCode)  }}
        </template>
      </el-table-column>
      <el-table-column
          label="薪资范围"
          align="center"
          show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.minSalary }}K-{{ scope.row.maxSalary }}K
        </template>
      </el-table-column>
      <el-table-column
          label="职位状态"
          align="center"
          show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.jobState == 1 ? '上架' : '下架' }}
        </template>
      </el-table-column>
      <el-table-column
          label="发布时间"
          prop="createTime"
          sortable
          align="center"
          width="170%"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="操作"
          align="center"
          width="240%">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="light" content="上架" placement="top" >
            <el-button v-show="scope.row.jobState == 0" style="margin-left: 10px" @click="disableHandle(scope.row.jobId,scope.row.jobName,scope.row.jobState)" type="warning" size="mini" class="iconfont icon-xiajiaxiawu"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="light" content="下架" placement="top" >
            <el-button v-show="scope.row.jobState == 1" @click="disableHandle(scope.row.jobId,scope.row.jobName,scope.row.jobState)" type="success" size="mini" class="iconfont icon-shangjia"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="light" content="详细信息" placement="top" >
            <el-button @click="detailInfo(scope.row)" class="iconfont icon-xiangqing" size="mini" type="success"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="light" content="删除" placement="top" >
            <el-button @click="deleteHandle(scope.row.jobId,scope.row.jobName)" size="mini" icon="el-icon-delete"
                       type="danger"></el-button>
          </el-tooltip>

        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        background
        layout="total,prev, pager, next"
        :total="total"
        align="center"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="pageSize"
        :hide-on-single-page="value"
        style="padding-top: 15px"
    >
    </el-pagination>
    <el-dialog title="职位详细信息" center :visible.sync="detailInfoVisible" width="60%" :close-on-click-modal="false"
               :lock-scroll="false">
      <el-descriptions direction="horizontal" :column="3" size="small" border>
        <el-descriptions-item>
          <template slot="label">
            职位名称
          </template>
          {{ job.jobName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            发布账号
          </template>
          {{ job.userName }}
        </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          发布人
        </template>
        {{ job.realName }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          所属公司
        </template>
        {{ job.companyName }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          薪资范围
        </template>
        {{ job.minSalary }}K-{{ job.maxSalary }}K
      </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            工作城市
          </template>
          {{codeToCity(job.cityCode)  }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            职位属性
          </template>
          {{ job.property==1?'校园招聘':'社会招聘' }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            工作形式
          </template>
          {{ job.jobPattern }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            所需经验
          </template>
          {{ job.experience }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            最低学历
          </template>
          {{ job.minEdu }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            招聘数量
          </template>
          {{ job.recruitNumber }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            职位类型
          </template>
          {{ job.jobCategory }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            所需专业
          </template>
          {{ job.professional }}
        </el-descriptions-item>
        <el-descriptions-item :span="2">
          <template slot="label">
            福利
          </template>
          {{ job.welfare }}
        </el-descriptions-item>
        <el-descriptions-item :sapn="3" label-style="width:90px">
          <template slot="label">
            职位描述
          </template>
          {{ job.jobInfo }}
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>

<script>
import {delJob, getJobList, shelveJob,} from "../../network/admin";
import {CodeToText} from "element-china-area-data";

export default {
  name: "JobList",
  data() {
    return {
      jobList: [],
      job: {},
      loading: true,
      keywords: '',
      value: false,
      currentPage: 1,
      total: 1,
      pageSize: 9,
      detailInfoVisible: false,
    }
  },

  created() {
    this.handleCurrentChange(this.currentPage);
  },
  methods: {
    handleCurrentChange(currentPage) {
      getJobList(this.keywords, currentPage, this.pageSize).then(res => {
        this.loading = false;
        this.total = res.data.data.total;
        this.jobList = res.data.data.list;
        this.currentPage = currentPage;
      })
    },
    codeToCity(code){
      return CodeToText[code];
    },
    searchHandle() {
      this.currentPage = 1;
      this.handleCurrentChange(this.currentPage)
    },
    deleteHandle(jobId, jobName) {
      this.$confirm('你确定要删除职位"' + jobName + '"吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delJob(jobId).then(res => {
          this.$message.success('职位' + jobName + res.data.data);
          this.handleCurrentChange(this.currentPage)
        }).catch()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
      });
    },
    disableHandle(jobId, jobName, jobState) {
      shelveJob(jobId).then(res => {
        if (res.data.code == 100) {
          this.$message.success('职位' + jobName + (jobState == 1 ? '下架' : '上架') + '成功');
        }
        this.handleCurrentChange(this.currentPage)
      }).catch()
    },
    indexMethod(index) {
      return (this.currentPage - 1) * this.pageSize + 1 + index;
    },
    detailInfo(job) {
      this.detailInfoVisible = true;
      this.job = job;
    }

  }
}
</script>

<style scoped>
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  min-width: 130px;
  height: 50px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-left: 50px;
  margin-bottom: 0;
  width: 40%;
}

.el-form-item__content {
  height: 50px;
}
</style>